﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RedfieldWeather
{
	public partial class CurrentForecast : System.Web.UI.UserControl
	{
		RFW.Weather.CurrentConditions _cc = new RFW.Weather.CurrentConditions();

		protected void Page_Load(object sender, EventArgs e)
		{
			_cc.DownloadComplete += _currentConditions_DownloadComplete;

			if (!this.IsPostBack)
				_cc.Get();
		}

		void _currentConditions_DownloadComplete(object sender, EventArgs e)
		{
			lblForecast.Text = _cc.Forecast.ToString();
			lblLastUpdated.Text = _cc.TimeStamp.ToString("R");

			Temperature.SetCurrentConditions(_cc);
			Winds.SetCurrentConditions(_cc);
			Rain.SetCurrentConditions(_cc);
			Barometer.SetCurrentConditions(_cc);
			Solar.SetCurrentConditions(_cc);
		}

		public void UpdateForecast()
		{
			_cc.Get();
		}
	}
}